//
//  MeViewController.m
//  gushihui
//
//  Created by 甘世清 on 2024/1/24.
//

#import "MeViewController.h"
#import "SetInfoViewController.h"
#import "AppRecommendedPopView.h"
#import "MeTopView.h"
#import "MeTableViewCell.h"
#import "MyMiDouViewController.h"
#import "CollectViewController.h"
#import "MyMapViewController.h"
#import "MyFunyViewController.h"

#import "SetViewController.h"
@interface MeViewController ()<UITableViewDelegate,UITableViewDataSource>
@property(nonatomic , strong) MeTopView * topView;
@property (nonatomic, strong) AppRecommendedPopView * footViews;

@end

@implementation MeViewController
- (void)SQ_viewWillAppear:(BOOL)animated{
    [self SQ_Header];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    WS(weakSelf);
    self.zx_navTitle = SQNSLocalString(@"我的");
    [self zx_setRightBtnWithImg:SQGetImage(@"shezhi") clickedBlock:^(ZXNavItemBtn * _Nonnull btn) {
        SetViewController * vc = [[SetViewController alloc]init];
        [weakSelf SQ_pushViewControllerFull:vc];
    }];
}
- (void)SQ_UIViewForSelfView{
    UIImageView * bg = [[UIImageView alloc]init];
    bg.image = SQGetImage(@"me背景");
    bg.contentMode = UIViewContentModeScaleAspectFill;
    [self.view addSubview:bg];
    [bg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.view);
    }];
    self.tableView.tableHeaderView = self.topView;
    [self.view addSubview:self.tableView];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.view).insets(UIEdgeInsetsMake(0, 0, FootHeight+50, 0));
    }];
    
    [self.view addSubview:self.footViews];
    [self.footViews mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(self.view);
        make.height.mas_equalTo(70);
        make.bottom.equalTo(self.view.mas_bottom).offset(-FootHeight-50);
    }];
    NSString * valuue = [Manager SQ_stringForKey:@"app_recommended_switch"];
    if ([valuue isEqualToString:@"1"]) {
        [self.tableView mas_updateConstraints:^(MASConstraintMaker *make) {
           make.edges.equalTo(self.view).insets(UIEdgeInsetsMake(0, 0, FootHeight+120, 0));
        }];
    }else{
        self.footViews.hidden = YES;
    }
    [self SQ_tableViewAddRefresh];
    [self.topView SQ_setdata];
    [self SQ_JsonArray];
}
- (void)SQ_Header{
    NSMutableDictionary * dic = [[NSMutableDictionary alloc]init];
    [HttpTool post:Url6 paramDic:dic successBlock:^(BaseModel * _Nonnull httpModel) {
        [MeModel SQ_setuserModel:httpModel];
        [self.topView SQ_setdata];
        [self SQ_JsonArray];
        [self.tableView.mj_header endRefreshing];
    } andFailBloc:^(BaseModel * _Nonnull httpModel, NSError * _Nullable error) {
        [YJProgressHUD showMsgWithoutView:httpModel.message];
        [self.tableView.mj_header endRefreshing];
    }];
}
- (void)SQ_Foother{
    [self.tableView.mj_footer endRefreshing];
}
-(void)SQ_JsonArray{
    [self.jsonArray removeAllObjects];
    //,@"协议内容",@"关于我们",@"注销账号",@"退出登录"
    NSArray * array = @[@"完善资料",@"我的收藏",@"我的动态",@"我的觅点",@"给个好评"];
    for (NSString * string in array) {
        [self.jsonArray addObject:string];
    }
    [self.topView SQ_setdata];
    [self.tableView reloadData];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
     return self.jsonArray.count;
}
 
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    MeTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MeTableViewCell"];
    if (!cell) {
        cell = [[MeTableViewCell alloc] initWithStyle:(UITableViewCellStyleValue1) reuseIdentifier:@"MeTableViewCell"];
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.name =  [self.jsonArray objectAtIndex:indexPath.item];
    return cell;
}
 

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return  66;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    NSString * name = [self.jsonArray objectAtIndex:indexPath.item];
    
    
      if ([name isEqualToString:@"我的收藏"]) {
        CollectViewController * vc = [[CollectViewController alloc]init];
        [self SQ_pushViewControllerFull:vc];
    }else  if ([name isEqualToString:@"我的觅点"]) {
        MyMapViewController * vc = [[MyMapViewController alloc]init];
        [self SQ_pushViewControllerFull:vc];
    }else if ([name isEqualToString:@"完善资料"]) {
        SetInfoViewController * vc = [[SetInfoViewController alloc]init];
        [self SQ_pushViewControllerFull:vc];
    }else  if ([name isEqualToString:@"我的动态"]) {
        MyFunyViewController * vc = [[MyFunyViewController alloc]init];
        [self SQ_pushViewControllerFull:vc];
    }else  if ([name isEqualToString:@"给个好评"]) {
       
        NSString *str = [NSString stringWithFormat:@"itms-apps://itunes.apple.com/app/id6483865713"];
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:str] options:@{} completionHandler:^(BOOL success) {
        }];
    }
}

- (MeTopView *)topView{
    if (!_topView) {
        _topView = [[MeTopView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDETH, 360)];
    }
    return _topView;
}
- (AppRecommendedPopView *)footViews{
    if (!_footViews) {
        _footViews = [[AppRecommendedPopView alloc]init];
    }
    return _footViews;
}
@end
